package com.qjz.diancan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qjz.diancan.mapper.CategoryMapper;
import com.qjz.diancan.model.entity.Category;
import com.qjz.diancan.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public PageInfo<Category> findByPage(Integer pageNum, Integer pageSize)
    {
        PageHelper.startPage(pageNum, pageSize);
        List<Category> categoryList = categoryMapper.selectAll();
        return new PageInfo<>(categoryList);
    }

    @Override
    @Transactional
    public void addCategory(Category category)
    {
        categoryMapper.insert(category);
    }

    @Override
    @Transactional
    public void deleteCate(Integer id)
    {
        categoryMapper.deleteById(id);
    }

    @Override
    @Transactional
    public void updateCate(Category category)
    {
        categoryMapper.update(category);
    }
}
